package com.buiminhthang.food.custom;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.buiminhthang.food.R;

public class CustomAdapter extends BaseAdapter {
	Context context;
	List<ListFood> listFood;

	public CustomAdapter(Context context, List<ListFood> listFood) {
		this.context = context;
		this.listFood = listFood;
	}

	/* private view holder class */
	private class ViewHolder {
		ImageView txtThumbnail;
		TextView txtTitle, txtPeople, txtTime;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;

		LayoutInflater mInflater = (LayoutInflater) context
				.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.activity_item_food, null);
			holder = new ViewHolder();
			holder.txtTitle = (TextView) convertView.findViewById(R.id.tvTitle);
			holder.txtPeople = (TextView) convertView
					.findViewById(R.id.tvPeople);
			holder.txtTime = (TextView) convertView.findViewById(R.id.tvTime);
			holder.txtThumbnail = (ImageView) convertView
					.findViewById(R.id.thumbnail);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		ListFood foodItem = (ListFood) getItem(position);

		holder.txtTitle.setText(foodItem.getTitle());
		holder.txtPeople.setText(foodItem.getPeople());
		holder.txtTime.setText(foodItem.getTime());
		holder.txtThumbnail.setImageResource(foodItem.getThumbnailId());

		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listFood.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listFood.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return listFood.indexOf(getItem(position));
	}

}